from fastapi import FastAPI,Form,HTTPException
import pymysql
app=FastAPI()
@app.post("/update")
def change(id:int=Form(...),status:str=Form(...)):
    global conn, cursor
    try:
        # 链接数据库
        conn=pymysql.Connection(user="root",password="Aa1234567.",database="p")
        # 创建游标对象
        cursor=conn.cursor()
        # 执行SQL语句
        a=cursor.execute("update deal set status = %s where id = %s",(status,id))
        # 提交SQL语句信息
        conn.commit()
        # 判定对象
        if a is None:
            # 失败案例
            raise HTTPException(400,"修改失败")
        else:
            # 成功案例
            return {"msg":a}
    except Exception as e:
          print(e)
          raise
    finally:
        # 关闭资源
        cursor.close()
        conn.close()